# Created by: Joe Marcus Clarke <marcus@FreeBSD.org>
# $FreeBSD: head/editors/abiword/Makefile 375598 2014-12-25 20:54:41Z bapt $
#   $MCom: ports/editors/abiword/Makefile,v 1.13 2009/11/10 13:56:18 kwm Exp $

PORTNAME=	abiword
PORTVERSION=	3.0.1
CATEGORIES=	editors
MASTER_SITES=	http://www.abisource.com/downloads/%SUBDIR%/${PORTVERSION}/source/
MASTER_SITE_SUBDIR=	abiword
DIST_SUBDIR=	AbiWord

MAINTAINER=	gnome@FreeBSD.org
COMMENT=	Open-source, cross-platform WYSIWYG word processor

LIB_DEPENDS=	libpopt.so:${PORTSDIR}/devel/popt \
		libpng.so:${PORTSDIR}/graphics/png \
		libwv.so:${PORTSDIR}/textproc/wv \
		libjpeg.so:${PORTSDIR}/graphics/jpeg \
		libfribidi.so:${PORTSDIR}/converters/fribidi \
		libgoffice-0.10.so:${PORTSDIR}/devel/goffice010 \
		libboost_system.so:${PORTSDIR}/devel/boost-libs
RUN_DEPENDS=	dejavu>0:${PORTSDIR}/x11-fonts/dejavu

LICENSE=	GPLv2
LICENSE_FILE=	${WRKSRC}/COPYING

BROKEN=	Core dump (assertion failed)

USES=		desktop-file-utils gettext gmake iconv libtool pkgconfig \
		python:2,build
USE_GNOME=	glib20 gtk30 librsvg2 libxslt introspection:build
GNU_CONFIGURE=	yes
CPPFLAGS+=	-I${LOCALBASE}/include
LDFLAGS+=	-L${LOCALBASE}/lib
CONFIGURE_ARGS=	--without-gnomevfs --enable-plugins="${ABIWORD_PLUGINS}" \
		enable_dynamic="yes" enable_static="no" \
		--enable-introspection=yes \
		--disable-collab-backend-telepathy \
		--disable-collab-backend-sugar \
		--disable-collab-backend-xmpp \
		--with-gio \
		--with-boost=yes \
		--without-libical
USE_LDCONFIG=	yes
INSTALLS_ICONS=	yes
INSTALL_TARGET=	install-strip

PLIST_SUB+=	ABIVERSION=${PORTVERSION:R}

OPTIONS_DEFINE=	DEBUG SPELLCHECK CLIPART TEMPLATES \
		OTS WP GRAMMAR
#OPTIONS_DEFAULT=SPELLCHECK CLIPART TEMPLATES COLLAB
OPTIONS_DEFAULT=SPELLCHECK CLIPART TEMPLATES

#OPTIONS_GROUP=	COLLAB
#OPTIONS_GROUP_COLLAB=	COLXMPP

SPELLCHECK_DESC=	Spell checking support
CLIPART_DESC=		Include clipart
TEMPLATES_DESC=		Include additional templates
#COLLAB_DESC=		Collaboration backend
#COLXMPP_DESC=		Collaboration jammer/XMPP backend
OTS_DESC=		Text Summarizer plugin
WP_DESC=		WordPerfect img/doc import/export plugin
GRAMMAR_DESC=		Grammar checking plugin

# check configure for ALL_PLUGINS for complete list
ABIWORD_PLUGINS=	garble loadbindings opml xslfo bmp iscii sdw babelfish \
			paint command latex pdf wikipedia hrtext openxml \
			goffice wmf kword mif wml s5 freetranslation gdict mht \
			applix t602 docbook google eml hancom presentation \
			clarisworks pdb urldict openwriter mswrite gimp \
			passepartout collab eml

# opendocument enabled by default, rsvg plugin isn't needed on unix.
# Plugins we don't support:
# gda

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MOTS}
LIB_DEPENDS+=	libots-1.so:${PORTSDIR}/textproc/ots
ABIWORD_PLUGINS:=	${ABIWORD_PLUGINS} ots
PLIST_SUB+=	OTS=""
.else
PLIST_SUB+=	OTS="@comment "
.endif

.if ${PORT_OPTIONS:MWP}
USE_GNOME+=	libgsf
LIB_DEPENDS+=	libwpg-0.2.so:${PORTSDIR}/graphics/libwpg \
		libwpd-0.9.so:${PORTSDIR}/textproc/libwpd
ABIWORD_PLUGINS:=	${ABIWORD_PLUGINS} wpg wordperfect
PLIST_SUB+=	WP=""
.else
PLIST_SUB+=	WP="@comment "
.endif

.if ${PORT_OPTIONS:MGRAMMAR}
LIB_DEPENDS+=	liblink-grammar.so:${PORTSDIR}/textproc/link-grammar
ABIWORD_PLUGINS:=	${ABIWORD_PLUGINS} grammar
PLIST_SUB+=	GRAMMAR=""
.else
PLIST_SUB+=	GRAMMAR="@comment "
.endif

#.if ! ${PORT_OPTIONS:MCOLLAB} && ${PORT_OPTIONS:MCOLXMPP}
#BROKEN=		Please enable the COLLAB option, the COLXMPP option need it.
#.endif

#.if ${PORT_OPTIONS:MCOLXMPP}
#CONFIGURE_ARGS+=--enable-collab-backend-xmpp
#LIB_DEPENDS+=	libloudmouth-1.so:${PORTSDIR}/net-im/loudmouth
#.else
#CONFIGURE_ARGS+=--disable-collab-backend-xmpp
#.endif

.if ${PORT_OPTIONS:MDEBUG}
CONFIGURE_ARGS+=	--enable-debug --enable-symbols
.endif

#.if ${PORT_OPTIONS:MCOLLAB}
#CONFIGURE_ARGS+=--with-boost --enable-collab-backend-tcp \
#		--enable-collab-backend-service
#BUILD_DEPENDS+=	${LOCALBASE}/include/asio.hpp:${PORTSDIR}/net/asio
#LIB_DEPENDS+=	libboost_system.so:${PORTSDIR}/devel/boost-libs \
#		libsoup-2.4.so:${PORTSDIR}/devel/libsoup \
#		libgnutls.so:${PORTSDIR}/security/gnutls
#RUN_DEPENDS+=	${LOCALBASE}/include/asio.hpp:${PORTSDIR}/net/asio
#PLIST_SUB+=		COLLAB=""
#.else
#CONFIGURE_ARGS+=--without-boost --disable-collab-backend-tcp \
#		--disable-collab-backend-service
#PLIST_SUB+=		COLLAB="@comment "
#.endif

.if ${PORT_OPTIONS:MSPELLCHECK}
LIB_DEPENDS+=		libenchant.so:${PORTSDIR}/textproc/enchant
CONFIGURE_ARGS+=	--enable-spell
PLIST_SUB+=		DICT=""
.else
CONFIGURE_ARGS+=	--disable-spell
PLIST_SUB+=		DICT="@comment "
.endif

.if ${PORT_OPTIONS:MTEMPLATES}
CONFIGURE_ARGS+=	--enable-templates
PLIST_SUB+=		TEMPLATES=""
.else
CONFIGURE_ARGS+=	--disable-templates
PLIST_SUB+=		TEMPLATES="@comment "
.endif

.if ${PORT_OPTIONS:MCLIPART}
CONFIGURE_ARGS+=	--enable-clipart
PLIST_SUB+=		CLIPART=""
.else
CONFIGURE_ARGS+=	--disable-clipart
PLIST_SUB+=		CLIPART="@comment "
.endif

post-patch:
# The following substitutions ensure that plugins are linked with libabiword
# from the work or stage directory instead of a previously installed library.
# In pseudo code:
# s,PLUGIN_LIBS="$PLUGIN_LIBS -Lsrc -labiword",
#   PLUGIN_LIBS="src/libabiword.la $PLUGIN_LIBS",
# s,foo_LIBS="$foo_LIBS $PLUGIN_LIBS",
#   foo_LIBS="$PLUGIN_LIBS $foo_LIBS",
# The initial value of PLUGIN_LIBS may contain -L/usr/local/lib so it would
# have to come after -Lsrc, but -Lsrc is not correct when libtool relinks
# plugins during staging so use src/libabiword.la and let libtool figure out
# what flags are needed.  Secondly, switch around foo_LIBS and PLUGIN_LIBS
# because foo_LIBS may contain -L/usr/local/lib.
	@${REINPLACE_CMD} \
		-e "s,\$$PLUGIN_LIBS \"'-L\$${top_builddir}/src'\" -labiword-\$$ABIWORD_SERIES,\\\\\$${top_builddir}/src/libabiword-\$$ABIWORD_SERIES.la \$$PLUGIN_LIBS," \
		-e "/_LIBS=/s,\"\\(.*\\)\"\\('\$${PLUGIN_LIBS}.*'\\),\\2\" \\1\"," \
		-e 's|" == "|" = "|g' ${WRKSRC}/configure
# Replace 'Times New Roman' police by 'DejaVu Serif' in templates and other
# files.
	${FIND} ${WRKSRC} -type f | \
		${XARGS} ${REINPLACE_CMD} -i "" "s,Times New Roman,DejaVu Serif,g"
	${FIND} ${WRKSRC} -type f -name 'Makefile.in' | \
		${XARGS} ${REINPLACE_CMD} -e "s|_la_LDFLAGS =|_la_LDFLAGS = -Wl,|"

.include <bsd.port.mk>
